package Hxw3DEngine.asset
{
	import Hxw3DEngine.asset.event.AssetEvent;
	import Hxw3DEngine.asset.loader.AssetLoader;
	import Hxw3DEngine.error.ErrorType;
	
	import flash.utils.Dictionary;
	
	/**
	 *资源总管理 					暂时没有加加载优先顺序
	 * @author huangxw
	 */		
	public class AssetManage
	{
		
		private static var _insdance:AssetManage;
		
		private static function get insdance():AssetManage{
			return _insdance ||= new AssetManage;
		}
		
		private var assetHash:Dictionary;
		
		
		public function AssetManage()
		{
			if(_insdance) throw new Error(ErrorType.SINGLE_ERROR);
			assetHash = new Dictionary;
		}
		
		
		//------------------------全局方法--------------------------------------
		
		/**
		 *时时的加载单个资源，只管加载不管其它任何的处理 
		 * @param url
		 * @param callBack
		 */		
		public static function load(url:String,callBack:Function = null):void{
			var data:* = getAsset(url);
			if(data){
				callBack();
			}else{
				var loader:AssetLoader = new AssetLoader();
				loader.load(url,callBack);
			}
		}
		
		public static function getAsset(url:String):*{
			var dic:Dictionary = insdance.assetHash;
			if(insdance.assetHash[url]){
				return insdance.assetHash[url];
			}
			return null ;
		}
		
		public static function deleteAsset(key:String):void{
			insdance.assetHash[key] = null ;
			delete insdance.assetHash[key];
		}
		
		public static function addAsset(key:String,data:*):void{
			insdance.assetHash[key] = data;
		}
		
	}
}